package com.shekhar.shortnotes.service;

import com.shekhar.shortnotes.domain.Note;
import com.shekhar.shortnotes.domain.Notebook;

import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

public class NoteServiceImpl implements NoteService {

    @Autowired
    private MongoTemplate mongoTemplate;
    
    public Note findNote(ObjectId notebookId,String noteId) {
        Note[] notes = mongoTemplate.findOne(new Query(Criteria.where("_id").is(notebookId).and("notes").elemMatch(Criteria.where("_id").is(noteId))), Notebook.class).getNotes();
        return notes[0];
    }
}
